﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using CRMAdapter;
using System.Data;
using System.IO;
using System.Xml;

namespace CRMWeb
{
    /// <summary>
    /// Summary description for EziDebitService
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class EziDebitService : System.Web.Services.WebService
    {

        [WebMethod]
        public XmlDocument addCustomer(string DigitalKey, string YourSystemReference, string YourGeneralReference, string LastName, string FirstName, string AddressLine1, string AddressLine2, string AddressSuburb, string AddressState, string AddressPostCode, string EmailAddress, string MobilePhoneNumber, string ContractStartDate, string SmsPaymentReminder, string SmsFailedNotification, string SmsExpiredCard, string Username)
        {
            XmlDocument res;
            try
            {
                res = PayByEzidebit.AddCustomers(DigitalKey, YourSystemReference, YourGeneralReference, LastName, FirstName, AddressLine1, AddressLine2, AddressSuburb, AddressState, AddressPostCode, EmailAddress, MobilePhoneNumber, ContractStartDate, SmsPaymentReminder, SmsFailedNotification, SmsExpiredCard, Username);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return res;
        }

        [WebMethod]
        public XmlDocument getPayments(string DigitalKey, string PaymentType, string PaymentMethod, string PaymentSource, string PaymentReference, string DateFrom, string DateTo, string DateField, string EzidebitCustomerID, string YourSystemReference)
        {
            XmlDocument res;
            try
            {
                res = PayByEzidebit.GetPayments(DigitalKey, PaymentType, PaymentMethod, PaymentSource, PaymentReference, DateFrom, DateTo, DateField, EzidebitCustomerID, YourSystemReference);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return res;
        }

        [WebMethod]
        public string editCustomer(string DigitalKey, string YourSystemReference, string YourGeneralReference, string LastName, string FirstName, string AddressLine1, string AddressLine2, string AddressSuburb, string AddressState, string AddressPostCode, string EmailAddress, string MobilePhoneNumber, string SmsPaymentReminder, string SmsFailedNotification, string SmsExpiredCard, string Username)
        {
            string res;
            try
            {
                res = PayByEzidebit.EditCustomers(DigitalKey, YourSystemReference, YourGeneralReference, LastName, FirstName, AddressLine1, AddressLine2, AddressSuburb, AddressState, AddressPostCode, EmailAddress, MobilePhoneNumber, SmsPaymentReminder, SmsFailedNotification, SmsExpiredCard, Username);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return res;
        }

        [WebMethod]
        public string createSchedule(string DigitalKey, string YourSystemReference, string ScheduleStartDate, string SchedulePeriodType, string DayOfWeek, int DayOfMonth, string FirstWeekOfMonth, string SecondWeekOfMonth, string ThirdWeekOfMonth, string FourthWeekOfMonth, long PaymentAmountInCents, int LimitToNumberOfPayments, long LimitToTotalAmountInCents, string KeepManualPayments, string Username)
        {
            string res;
            try
            {
                res = PayByEzidebit.CreateSchedule(DigitalKey, YourSystemReference, ScheduleStartDate, SchedulePeriodType, DayOfWeek, DayOfMonth, FirstWeekOfMonth, SecondWeekOfMonth, ThirdWeekOfMonth, FourthWeekOfMonth, PaymentAmountInCents, LimitToNumberOfPayments, LimitToTotalAmountInCents, KeepManualPayments, Username);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return res;
        }

        [WebMethod]
        public XmlDocument getScheduledPayments(string DigitalKey, string DateFrom, string DateTo, string EziDebitCustomerID, string YourSystemReference)
        {
            XmlDocument res;
            try
            {
                res = PayByEzidebit.GetScheduledPayments(DigitalKey, DateFrom, DateTo, EziDebitCustomerID, YourSystemReference);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return res;
        }

        [WebMethod]
        public XmlDocument getCustomerDetails(string DigitalKey, string EziDebitCustomerID, string YourSystemReference)
        {
            XmlDocument res;
            try
            {
                res = PayByEzidebit.GetCustomerDetails(DigitalKey, EziDebitCustomerID, YourSystemReference);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return res;
        }

        [WebMethod]
        public XmlDocument GetPaymentDetailPlusNextPaymentInfo(string DigitalKey, string PaymentReference)
        {
            XmlDocument res;
            try
            {
                res = PayByEzidebit.GetPaymentDetailPlusNextPaymentInfo(DigitalKey, PaymentReference);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return res;
        }

        [WebMethod]
        public string GetPaymentStatus(string DigitalKey, string PaymentReference)
        {
            string res;
            try
            {
                res = PayByEzidebit.GetPaymentStatus(DigitalKey, PaymentReference);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return res;
        }

        [WebMethod]
        public XmlDocument GetPaymentDetails(string DigitalKey, string PaymentReference)
        {
            XmlDocument res;
            try
            {
                res = PayByEzidebit.GetPaymentDetails(DigitalKey, PaymentReference);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return res;
        }

        [WebMethod]
        public string ClearSchedule(string DigitalKey, string EziDebitCustomerID, string YourSystemReference, string KeepManualPayments, string Username)
        {
            string res;
            try
            {
                res = PayByEzidebit.ClearSchedule(DigitalKey, EziDebitCustomerID, YourSystemReference, KeepManualPayments, Username);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return res;
        }

        [WebMethod]
        public string DeletePayment(string DigitalKey, string EziDebitCustomerID, string YourSystemReference, string PaymentReference, string DebitDate, long PaymentAmountInCents, string Username)
        {
            string res;
            try
            {
                res = PayByEzidebit.DeletePayment(DigitalKey, EziDebitCustomerID, YourSystemReference, PaymentReference, DebitDate, PaymentAmountInCents, Username);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return res;
        }

        [WebMethod]
        public string IsBsbValid(string DigitalKey, string BankAccountBSB)
        {
            string res;
            try
            {
                res = PayByEzidebit.IsBsbValid(DigitalKey, BankAccountBSB);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return res;
        }

        [WebMethod]
        public string IsSystemLocked(string DigitalKey)
        {
            string res;
            try
            {
                res = PayByEzidebit.IsSystemLocked(DigitalKey);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return res;
        }

        [WebMethod]
        public string PaymentExchangeVersion()
        {
            string res;
            try
            {
                res = PayByEzidebit.PaymentExchangeVersion();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return res;
        }

        [WebMethod]
        public string ChangeCustomerStatus(string DigitalKey, string EziDebitCustomerID, string YourSystemReference, string NewStatus, string Username)
        {
            string res;
            try
            {
                res = PayByEzidebit.ChangeCustomerStatus(DigitalKey, EziDebitCustomerID, YourSystemReference, NewStatus, Username);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return res;
        }

        [WebMethod]
        public string ChangeScheduledAmounts(string DigitalKey, string EziDebitCustomerID, string YourSystemReference, int ChangeFromPaymentNumber, string ChangeFromDate, long NewPaymentAmountInCents, string ApplyToAllFuturePayments, string KeepManualPayments, string Username)
        {
            string res;
            try
            {
                res = PayByEzidebit.ChangeScheduledAmounts(DigitalKey, EziDebitCustomerID, YourSystemReference, ChangeFromPaymentNumber, ChangeFromDate, NewPaymentAmountInCents, ApplyToAllFuturePayments, KeepManualPayments, Username);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return res;
        }

        [WebMethod]
        public string ChangeScheduledDates(string DigitalKey, string EziDebitCustomerID, string YourSystemReference, string ChangeFromDate, string PaymentReference, string ChangeToDate, string KeepManualPayments, string Username)
        {
            string res;
            try
            {
                res = PayByEzidebit.ChangeScheduledDates(DigitalKey, EziDebitCustomerID, YourSystemReference, ChangeFromDate, PaymentReference, ChangeToDate, KeepManualPayments, Username);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return res;
        }
      
        [WebMethod]
        public string AddPayments(string DigitalKey, string EziDebitCustomerID, string YourSystemReference, string DebitDate, long PaymentAmountInCents, string PaymentReference, string Username)
        {
            string res;
            try
            {
                res = PayByEzidebit.AddPayments(DigitalKey, EziDebitCustomerID, YourSystemReference, DebitDate, PaymentAmountInCents, PaymentReference, Username);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return res;
        }
    
    }
}
